import datetime
import time

def array_to_string(arr):
    # 将数组中的元素转换为字符串
    str_arr = [str(item) for item in arr]
    # 使用逗号连接所有字符串
    result = "', '".join(str_arr)
    # 添加首尾的单引号
    result = f"'{result}'"
    return result
def get_filename_part():
# 获取当前时间
    now = datetime.datetime.now()
    # 生成字符串，格式为：年-月-日_时-分
    filename_part = now.strftime("_%Y%m%d%H%M")
    print(filename_part)
    return filename_part
get_filename_part()
def history_query(dbhelper, action,timeinterval=30):
    # 时间间隔内是否要处理
    intrecords=0
    sql=f'select * from las_task where ( TIMESTAMPDIFF(MINUTE, lastupdate_date, now()) <{timeinterval} or lastupdate_date is null) and taskname="{action}"'
    intrecords=dbhelper.query_one(sql)
    return intrecords
def history_writelog(dbhelper, action,object='',diskid=''):
    # 时间间隔内是否要处理
    intrecords=0
    sql=f'select * from app_diskblacklist where disk="{diskid}"'
    result_disk=dbhelper.query_one(sql)
    
    sql=f'insert into las_loghistory (action,opdate,obj) values ("{action}",now(),"{object}")'
    dbhelper.execute(sql)
    sql=f'select * from las_task where taskname="{action}"'
    result=dbhelper.query_one(sql)
    if len(result)>0:
        sql=f'update las_task set lastupdate_date=now() where taskname="{action}"'
        dbhelper.execute(sql)
        # print(f"记录task {action}成功")
    else:
        sql=f'insert into las_task (taskname,lastupdate_date) values ("{action}",now())'
        dbhelper.execute(sql)
        # print(f"记录task {action}成功")
    if len(result_disk)==0:
            return False
    else:
            return True

def sleep(seconds):
    try:
        time.sleep(seconds)
    except Exception as e:
        print(e)

# if __name__ == '__main__':

#     # history_query(dbhelper,"lingxing-downstore",24*60)
#     history_writelog(dbhelper,"qiuzhang-downmap")
#     a=234

        
